/**
 * 
 */
package com.elite.groovy.callback

import com.elite.groovy.util.EliteBean
import com.elite.groovy.util.Util
import net.sf.json.JSONObject
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory

import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse //导入grooby的json解析api包

/**
 * 
 * @author 智能回访结果回调，由MQ调用的智能外呼系统回调
 *
 */


 public  class receiveRabbitMq implements ServiceBackInvoke{
  public static final Log log = LogFactory.getLog(receiveRabbitMq.class);
  public String doCallBack(EliteBean eliteBean, HttpServletRequest request, HttpServletResponse response){
      log.debug("-----Begin Systeam----------");
      response.setHeader("Content-type", "text/html;charset=UTF-8");
      response.setCharacterEncoding("UTF-8");
      //String c_ContNo=request.getParameter("contNo");

      String requestJSONStr =Util.getRequestBody(request, "UTF-8");
      log.debug("requestJSONStr:" + requestJSONStr);
    
      JSONObject json  = new JSONObject().fromObject(requestJSONStr);
      String v_BusType = json.getString("BusType");        //场景类型
      String v_BusNum = json.getString("BusNum");        //任务标识(objective_guid)
      String v_VisitStatus = json.getString("VisitStatus");        //回访结果
      String v_VisitEndType = json.getString("VisitEndType");      //回访完成类型
      String v_CallLose = json.getString("CallLose");        //是否呼损
      String v_CallTime = json.getString("CallTime");        //外拨时间
      
      log.debug("v_BusType:"+v_BusType);
      log.debug("v_BusNum:"+v_BusNum);
      log.debug("v_VisitStatus:"+v_VisitStatus);
      log.debug("v_VisitEndType:"+v_VisitEndType);
      log.debug("v_CallLose:"+v_CallLose);
      log.debug("v_CallTime:"+v_CallTime);
    
                
      //数据效验
      def querysql1="select count(*) count1 from Ob_visitTask where visittask_guid='"+v_BusNum+"' and MODIFIEDDATE is null";
      def count1="";
      def list1=eliteBean.chaxun_sql(querysql1,"dataSource");
      log.debug("list-------------------------------"+list1);
      for(def k=0;k<list1.size();k++){
      def map1=list1[k];
      def v_count1=map1.get("count1");
      log.debug("v_count1---v_count1-----v_count1----"+v_count1);
	      
		  //更新回访推送中间表：智能回访状态、结果、外呼时间、呼损标记
		  def updatesql1="update Ob_visitTask set CallLose='"+v_CallLose+"',MODIFIEDDATE=sysdate,VisitStatus='"+v_VisitStatus+"',VisitEndType='"+v_VisitEndType+"',CallTime='"+v_CallTime+"' where visittask_guid='"+v_BusNum+"'";
          def updatesqlresult1=eliteBean.update(updatesql1,"dataSource");
          log.debug("updatesqlresult1:"+updatesqlresult1);
		
          //增值回访回传呼损执行
        if(v_count1>0&&v_BusType=='VAS'&&v_CallLose=='1'){

            //更新-- 车险增值   OBJECTIVE到回访环节
          def updatesql2="update objective set realvisiter_flag='1',HANDLEGROUP_ID='ORG016',OBJECTIVESUBSTATUS='',CURSTEP_ID_MAP='D2B8QB' where objective_guid =(select objective_guid from Ob_visitTask where visittask_guid= '"+v_BusNum+"' and MAP_ID='HWYY20')";
          def updatesqlresult2=eliteBean.update(updatesql2,"dataSource");
          log.debug("updatesqlresult2:"+updatesqlresult2);
		    //更新-- 非车险增值 OBJECTIVE到回访环节
          def updatesql3="update objective set realvisiter_flag='1',HANDLEGROUP_ID='ORG016',OBJECTIVESUBSTATUS='',CURSTEP_ID_MAP='JLNKLC' where objective_guid =(select objective_guid from Ob_visitTask where visittask_guid= '"+v_BusNum+"' and MAP_ID='K3ZK57')";
          def updatesqlresult3=eliteBean.update(updatesql3,"dataSource");
          log.debug("updatesqlresult3:"+updatesqlresult3);

			//更新-- 车险增值   ELITETASK到回访环节
          def updatesql4="update elitetask set OBFLAG='1',CURSTEP_ID='D2B8QB',CURSTEP_ID_MAP='D2B8QB',OBJECTIVESUBSTATUS='',HANDLEGROUP_ID='ORG016' where objective_guid =(select objective_guid from Ob_visitTask where visittask_guid= '"+v_BusNum+"' and MAP_ID='HWYY20')";
          def updatesqlresult4=eliteBean.update(updatesql4,"dataSource");
          log.debug("updatesqlresult4:"+updatesqlresult4);		  
            //更新-- 非车险增值 ELITETASK到回访环节
          def updatesql5="update elitetask set  OBFLAG='1',CURSTEP_ID='JLNKLC',CURSTEP_ID_MAP='JLNKLC',OBJECTIVESUBSTATUS='',HANDLEGROUP_ID='ORG016' where objective_guid =(select objective_guid from Ob_visitTask where visittask_guid= '"+v_BusNum+"' and MAP_ID='K3ZK57')";
          def updatesqlresult5=eliteBean.update(updatesql5,"dataSource");
          log.debug("updatesqlresult5:"+updatesqlresult5);			  
		  	//更新tabc表回访信息
		  def updatesql6="update tabcdh_vas_list  set  VISIT_TYPE='1',OUT_STAT_TYPE='"+v_VisitStatus+"',VISIT_END_STAT='"+v_VisitEndType+"',FIRST_VISIT_TIME='"+v_CallTime+"' where relation_id= '"+v_BusNum+"'";
          def updatesqlresult6=eliteBean.update(updatesql6,"dataSource");
          log.debug("updatesqlresult6:"+updatesqlresult6);
            //返回成功结果
          JSONObject  jsonALL3 = new JSONObject();
          jsonALL3.put("code", "200");
          jsonALL3.put("msg", "success");
          return jsonALL3;
        }
          //增值回访回传非呼损
        if(v_count1>0&&v_BusType=='VAS'&&v_CallLose=='0'){
          def querysql12="select createddate,createdby from objective where objective_guid =(select objective_guid from Ob_visitTask where visittask_guid= '"+v_BusNum+"')";
          def list12=eliteBean.chaxun_sql(querysql12,"dataSource");
          log.debug("list-------------------------------"+list12);
          def createddate,createdby;
          for(def j=0;j<list12.size();j++) {
            def map12=list12[j];
			log.debug("map12-------------------------------"+map12);

            createddate = map12.get("createddate");
            createdby= map12.get("createdby");
			log.debug("createddate-------------------------------"+createddate);
			log.debug("createdby-------------------------------"+createdby);
          }

            //更新obj办结状态
          def updatesql14="update objective set OBJECTIVESTATUS='CLOSE',curstep_id_map='KC17US' where objective_guid =(select objective_guid from Ob_visitTask where visittask_guid= '"+v_BusNum+"')";
          def updatesqlresult14=eliteBean.update(updatesql14,"dataSource");
          log.debug("updatesqlresult14:"+updatesqlresult14);
            //办结删除elitetask
          def updatesql15="delete from elitetask where objective_guid = (select objective_guid from Ob_visitTask where visittask_guid= '"+v_BusNum+"')";
          def updatesqlresult15=eliteBean.update(updatesql15,"dataSource");
          log.debug("updatesqlresult15:"+updatesqlresult15);
			//更新tabc表回访结果
		  def updatesql16="update tabcdh_vas_list  set  VISIT_TYPE='2',VISIT_END_TIME=sysdate,OUT_STAT_TYPE='"+v_VisitStatus+"',VISIT_END_STAT='"+v_VisitEndType+"',FIRST_VISIT_TIME='"+v_CallTime+"',SCHEDULER='"+createdby+"',SCHEDUL_TIME='"+createddate+"' where relation_id= (select objective_guid from Ob_visitTask where visittask_guid= '"+v_BusNum+"')";
          def updatesqlresult16=eliteBean.update(updatesql16,"dataSource");
          log.debug("updatesqlresult16:"+updatesqlresult16);
		  
            //返回成功结果
          JSONObject  jsonALL3 = new JSONObject();
          jsonALL3.put("code", "200");
          jsonALL3.put("msg", "success");
          return jsonALL3;
        }
		
		//报案、结案、承保新单非呼损
		if(v_count1>0&&(v_BusType=='REPORT'||v_BusType=='JA'||v_BusType=='POLICY')&&v_CallLose=='0'){

            //返回成功结果
          JSONObject  jsonALL3 = new JSONObject();
          jsonALL3.put("code", "200");
          jsonALL3.put("msg", "success");
          return jsonALL3;
        }
        
        
          //结案回访回传呼损执行
        if(v_count1>0&&v_BusType=='JA'&&v_CallLose=='1'){

            //检查customer是否存在
          def querysql21="select count(*) countja from customer cc ,(select c.PRPLREGISTREPORTORNAME a,c.PRPLREGISTREPORTORPHONENUMBER b from Ob_visitTask t left join COREUSER.CC_CORE_CASE_CLOSED c on c.REGISTNO=t.BUSINESSNO where visittask_guid= '"+v_BusNum+"')tt where cc.customername=tt.a and cc.mobile=tt.b and cc.fax is null";
          def countja="";
          def list21=eliteBean.chaxun_sql(querysql21,"dataSource");
          log.debug("list21-------------------------------"+list21);
		  def map21=list21[0];
		  log.debug("map21-------------------------------"+map21);
		  def v_countja=map21.get("countja");
          log.debug("v_countja-------------------------------"+v_countja);	  
            //无客户新建
            if(v_countja==0){
                //新customer_guid
              def querysql22="select sysguid v_ja_custguid from dual";
              def v_ja_custguid="";
              def list22=eliteBean.chaxun_sql(querysql22,"dataSource");
              log.debug("list22-------------------------------"+list22);
			  def map22=list22[0];
			  log.debug("map22-------------------------------"+map22);
			  def ja_custguid=map22.get("v_ja_custguid");
              log.debug("ja_custguid-------------------------------"+ja_custguid);
                //生成 customer
              def updatesql23="insert into customer(CUSTOMER_GUID,customertype_id,CUSTOMERNAME,MOBILE,WORKSTATUS)select '"+ja_custguid+"','KFjoin',c.PRPLREGISTREPORTORNAME a,c.PRPLREGISTREPORTORPHONENUMBER b,'ONLINE' from Ob_visitTask t left join COREUSER.CC_CORE_CASE_CLOSED c on c.REGISTNO=t.BUSINESSNO where visittask_guid= '"+v_BusNum+"'  and rownum=1";
              def updatesqlresult23=eliteBean.update(updatesql23,"dataSource");
              log.debug("updatesqlresult23:"+updatesqlresult23);
                //生成 objective
              def updatesql28="insert into objective (OBJECTIVE_GUID, OBJECTIVETYPE_ID, HANDLEGROUP_ID,PRIORITY_ID,EXPIREDDATE,CUSTOMER_GUID,OBJECTIVESTATUS,FIRSTCONTACTDATE,LASTCONTACTDATE,CREATEDDATE,CREATEDBY,WORKORDERFRAME_ID,OBJECTIVESUBSTATUS,MAP_ID,CURSTEP_ID_MAP)select objective_guid,'USZP59','ORG016','NORMAL',sysdate,'"+ja_custguid+"','OPEN',to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),CREATEDDATE,CREATEDBY,map_id,'OPEN',map_id,'PKWJHN' from Ob_visitTask where visittask_guid= '"+v_BusNum+"'";
              def updatesqlresult28=eliteBean.update(updatesql28,"dataSource");
              log.debug("updatesqlresult28:"+updatesqlresult28);
                //生成 elitetask 
              def updatesql24="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID, CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG) select sysguid,objective_guid,'USZP59',sysdate,'OPEN','NORMAL','ORG016',CREATEDBY,CREATEDDATE,'"+ja_custguid+"','OPEN','PKWJHN',MAP_ID,'OPEN','OPEN','1' FROM Ob_visitTask where visittask_guid='"+v_BusNum+"'";
              def updatesqlresult24=eliteBean.update(updatesql24,"dataSource");
              log.debug("updatesqlresult24:"+updatesqlresult24);              
            }
            //有客户
            if(v_countja>0){
                //获取customer_guid
              def querysql25="select cc.customer_guid v_ja_custguid  from customer cc ,(select c.PRPLREGISTREPORTORNAME a,c.PRPLREGISTREPORTORPHONENUMBER b from Ob_visitTask t left join COREUSER.CC_CORE_CASE_CLOSED c on c.REGISTNO=t.BUSINESSNO where visittask_guid= '"+v_BusNum+"')tt where cc.customername=tt.a and cc.mobile=tt.b and rownum=1";
              def v_ja_custguid="";
              def list25=eliteBean.chaxun_sql(querysql25,"dataSource");
              log.debug("list25-------------------------------"+list25);			  
			  def map25=list25[0];
			  log.debug("map25-------------------------------"+map25);
			  def ja_custguid=map25.get("v_ja_custguid");
              log.debug("ja_custguid-------------------------------"+ja_custguid);
                //生成 objective
              def updatesql26="insert into objective (OBJECTIVE_GUID, OBJECTIVETYPE_ID, HANDLEGROUP_ID,PRIORITY_ID,EXPIREDDATE,CUSTOMER_GUID,OBJECTIVESTATUS,FIRSTCONTACTDATE,LASTCONTACTDATE,CREATEDDATE,CREATEDBY,WORKORDERFRAME_ID,OBJECTIVESUBSTATUS,MAP_ID,CURSTEP_ID_MAP)select objective_guid,'USZP59','ORG016','NORMAL',sysdate,'"+ja_custguid+"','OPEN',to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),CREATEDDATE,CREATEDBY,map_id,'OPEN',map_id,'PKWJHN' from Ob_visitTask where visittask_guid='"+v_BusNum+"'";
              def updatesqlresult26=eliteBean.update(updatesql26,"dataSource");
              log.debug("updatesqlresult26:"+updatesqlresult26);
                //生成 elitetask 
              def updatesql27="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID, CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG) select sysguid,objective_guid,'USZP59',sysdate,'OPEN','NORMAL','ORG016',CREATEDBY,CREATEDDATE,'"+ja_custguid+"','OPEN','PKWJHN',MAP_ID,'OPEN','OPEN','1' FROM Ob_visitTask where visittask_guid='"+v_BusNum+"'";
              def updatesqlresult27=eliteBean.update(updatesql27,"dataSource");
              log.debug("updatesqlresult27:"+updatesqlresult27);    
            }
          
          
          //更新为可人工回访状态
          def updatesql92="update objective set realvisiter_flag='1' where objective_guid =(select objective_guid from Ob_visitTask where visittask_guid= '"+v_BusNum+"')";
          def updatesqlresult92=eliteBean.update(updatesql92,"dataSource");
          log.debug("updatesqlresult92:"+updatesqlresult92);
          //返回成功结果
          JSONObject  jsonALL3 = new JSONObject();
          jsonALL3.put("code", "200");
          jsonALL3.put("msg", "success");
          return jsonALL3;
        }
      
          //承保新单回访回传呼损执行
        if(v_count1>0&&v_BusType=='POLICY'&&v_CallLose=='1'){

         //20230323取消新单回访重新人工
        /*
            //检查customer是否存在
          def querysql31="select count(*) v_countxd from customer cc ,(select c.INSUREDNAME a,c.INSUREDMOBILE b from Ob_visitTask t left join dh_policy c on c.POLICYNO=t.BUSINESSNO where visittask_guid= '"+v_BusNum+"')tt where cc.customername=tt.a and cc.mobile=tt.b and cc.fax is null"
          def v_countxd=""
          def list31=eliteBean.chaxun_sql(querysql31,"dataSource")
          log.debug("list31-------------------------------"+list31)
          def map31=list31[0]
          log.debug("map31-------------------------------"+map31)
          def countxd=map31.get("v_countxd")
          log.debug("countxd-------------------------------"+countxd)
            //无客户新建
            if(countxd==0){
                //新customer_guid
              def querysql32="select sysguid xd_custguid from dual"
              //def xd_custguid="";
              def list32=eliteBean.chaxun_sql(querysql32,"dataSource")
              log.debug("list32-------------------------------"+list32)
              def xd_custguid=list32[0].get("xd_custguid")
              log.debug("xd_custguid-------------------------------"+xd_custguid)
              //生成 customer
              def updatesql33="insert into customer(CUSTOMER_GUID,customertype_id,CUSTOMERNAME,MOBILE,WORKSTATUS) select '"+xd_custguid+"','KFjoin',c.INSUREDNAME a,c.INSUREDMOBILE b,'ONLINE' from Ob_visitTask t left join dh_policy c on c.POLICYNO=t.BUSINESSNO where visittask_guid= '"+v_BusNum+"'  and rownum=1"
              def updatesqlresult33=eliteBean.update(updatesql33,"dataSource")
              log.debug("updatesqlresult33:"+updatesqlresult33)
              //生成 objective
              def updatesql38="insert into objective (OBJECTIVE_GUID, OBJECTIVETYPE_ID, HANDLEGROUP_ID,PRIORITY_ID,EXPIREDDATE,CUSTOMER_GUID,OBJECTIVESTATUS,FIRSTCONTACTDATE,LASTCONTACTDATE,CREATEDDATE,CREATEDBY,WORKORDERFRAME_ID,OBJECTIVESUBSTATUS,MAP_ID,CURSTEP_ID_MAP)select objective_guid,'USZP59','ORG016','NORMAL',sysdate,'"+xd_custguid+"','OPEN',to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),CREATEDDATE,CREATEDBY,map_id,'OPEN',map_id,'5JT51D' from Ob_visitTask where visittask_guid='"+v_BusNum+"'"
              def updatesqlresult38=eliteBean.update(updatesql38,"dataSource")
              log.debug("updatesqlresult38:"+updatesqlresult38)
              //生成 elitetask
              def updatesql34="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID, CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG) select sysguid,objective_guid,'USZP59',sysdate,'OPEN','NORMAL','ORG016',CREATEDBY,CREATEDDATE,'"+xd_custguid+"','OPEN','5JT51D',MAP_ID,'OPEN','OPEN','1' FROM Ob_visitTask where visittask_guid='"+v_BusNum+"'"
              def updatesqlresult34=eliteBean.update(updatesql34,"dataSource")
              log.debug("updatesqlresult34:"+updatesqlresult34)
            }
            //有客户
            if(countxd>0){
                //获取customer_guid
              def querysql35="select cc.customer_guid v_xd_custguid  from customer cc ,(select sd.insuredname a,sd.mobile b from Ob_visitTask v left join dh_POLICY sd on sd.PolicyNo=v.businessno where  v.visittask_guid= '"+v_BusNum+"')tt where cc.customername=tt.a and cc.mobile=tt.b and rownum=1"
              def v_xd_custguid=""
              def list35=eliteBean.chaxun_sql(querysql35,"dataSource")
              log.debug("list35-------------------------------"+list35)
			  def map35=list35[0]
              log.debug("map35-------------------------------"+map35)
              def xd_custguid=map35.get("v_xd_custguid")
              log.debug("xd_custguid-------------------------------"+xd_custguid)
                //生成 objective
              def updatesql36="insert into objective (OBJECTIVE_GUID, OBJECTIVETYPE_ID, HANDLEGROUP_ID,PRIORITY_ID,EXPIREDDATE,CUSTOMER_GUID,OBJECTIVESTATUS,FIRSTCONTACTDATE,LASTCONTACTDATE,CREATEDDATE,CREATEDBY,WORKORDERFRAME_ID,OBJECTIVESUBSTATUS,MAP_ID,CURSTEP_ID_MAP)select objective_guid,'USZP59','ORG016','NORMAL',sysdate,'"+xd_custguid+"','OPEN',to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),CREATEDDATE,CREATEDBY,map_id,'OPEN',map_id,'5JT51D' from Ob_visitTask where visittask_guid= '"+v_BusNum+"'"
              def updatesqlresult36=eliteBean.update(updatesql36,"dataSource")
              log.debug("updatesqlresult36:"+updatesqlresult36)
              //生成 elitetask
              def updatesql37="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID, CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG) select sysguid,objective_guid,'USZP59',sysdate,'OPEN','NORMAL','ORG016',CREATEDBY,CREATEDDATE,'"+xd_custguid+"','OPEN','5JT51D',MAP_ID,'OPEN','OPEN','1' FROM Ob_visitTask where visittask_guid='"+v_BusNum+"'"
              def updatesqlresult37=eliteBean.update(updatesql37,"dataSource")
              log.debug("updatesqlresult37:"+updatesqlresult37)
            }*/
          //返回成功结果
          JSONObject  jsonALL3 = new JSONObject();
          jsonALL3.put("code", "200");
          jsonALL3.put("msg", "success");
          return jsonALL3;
        }
        
          //报案回访回传呼损执行
        if(v_count1>0&&v_BusType=='REPORT'&&v_CallLose=='1'){
         //20230323取消报案重新人工回访
        /*
            //查询具体报案类型
          def querysql41="select BUSTYPE_REPORT BUSTYPE_REPORT from Ob_visitTask  where visittask_guid= '"+v_BusNum+"'"
          def BUSTYPE_REPORT=""
          def list41=eliteBean.chaxun_sql(querysql41,"dataSource")
          log.debug("list41-------------------------------"+list41)
		  def map41=list41[0]
          log.debug("map41-------------------------------"+map41)
          def V_BUSTYPE_REPORT=map41.get("BUSTYPE_REPORT")
          log.debug("V_BUSTYPE_REPORT-------------------------------"+V_BUSTYPE_REPORT)
            //检查customer是否存在
          def querysql42="select count(*) countba from customer cc ,(select r.reportor_name a,r.reportor_phone b from Ob_visitTask v left join DH_REPORT r on r.CLM_NO=v.businessno where  v.visittask_guid= '"+v_BusNum+"')tt where cc.customername=tt.a and cc.mobile=tt.b and cc.fax is null"
          //def countba="";
          def list42=eliteBean.chaxun_sql(querysql42,"dataSource")
          log.debug("list42-------------------------------"+list42)
          def countba=list42[0].get("countba")
          log.debug("countba-------------------------------"+countba)
          //无客户新建
            if(countba==0){
                //新customer_guid
              def querysql43="select sysguid v_ba_custguid from dual"
              def v_ba_custguid=""
              def list43=eliteBean.chaxun_sql(querysql43,"dataSource")
              log.debug("list43-------------------------------"+list43)
			  def map43=list43[0]
              log.debug("map43-------------------------------"+map43)
              def ba_custguid=map43.get("v_ba_custguid")
              log.debug("ba_custguid-------------------------------"+ba_custguid)
                //生成 customer
              def updatesql44="insert into customer(CUSTOMER_GUID,customertype_id,CUSTOMERNAME,MOBILE,WORKSTATUS) select '"+ba_custguid+"','KFjoin',c.linker_name a,c.linker_phone b,'ONLINE' from Ob_visitTask t left join dh_report c on c.clm_no=t.BUSINESSNO where visittask_guid= '"+v_BusNum+"'  and rownum=1"
              def updatesqlresult44=eliteBean.update(updatesql44,"dataSource")
              log.debug("updatesqlresult44:"+updatesqlresult44)
              //报案--现场查勘回访
                if(V_BUSTYPE_REPORT=='DDF'){
                    //生成 objective
                  def updatesql45="insert into objective (OBJECTIVE_GUID, OBJECTIVETYPE_ID, HANDLEGROUP_ID,PRIORITY_ID,EXPIREDDATE,CUSTOMER_GUID,OBJECTIVESTATUS,FIRSTCONTACTDATE,LASTCONTACTDATE,CREATEDDATE,CREATEDBY,WORKORDERFRAME_ID,OBJECTIVESUBSTATUS,MAP_ID,CURSTEP_ID_MAP)select objective_guid,'USZP59','ORG016','NORMAL',sysdate,'"+ba_custguid+"','OPEN',to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),CREATEDDATE,CREATEDBY,map_id,'OPEN',map_id,'UUANWS' from Ob_visitTask where visittask_guid='"+v_BusNum+"'"
                  def updatesqlresult45=eliteBean.update(updatesql45,"dataSource")
                  log.debug("updatesqlresult45:"+updatesqlresult45)
                  //生成 elitetask
                  def updatesql46="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID, CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG) select sysguid,objective_guid,'USZP59',sysdate,'OPEN','NORMAL','ORG016',CREATEDBY,CREATEDDATE,'"+ba_custguid+"','OPEN','UUANWS',MAP_ID,'OPEN','OPEN','1' FROM Ob_visitTask where visittask_guid='"+v_BusNum+"'"
                  def updatesqlresult46=eliteBean.update(updatesql46,"dataSource")
                  log.debug("updatesqlresult46:"+updatesqlresult46)
                }
                  //报案--非现场查勘回访
                if(V_BUSTYPE_REPORT=='DDE'){
                    //生成 objective
                  def updatesql47="insert into objective (OBJECTIVE_GUID, OBJECTIVETYPE_ID, HANDLEGROUP_ID,PRIORITY_ID,EXPIREDDATE,CUSTOMER_GUID,OBJECTIVESTATUS,FIRSTCONTACTDATE,LASTCONTACTDATE,CREATEDDATE,CREATEDBY,WORKORDERFRAME_ID,OBJECTIVESUBSTATUS,MAP_ID,CURSTEP_ID_MAP)select objective_guid,'USZP59','ORG016','NORMAL',sysdate,'"+ba_custguid+"','OPEN',to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),CREATEDDATE,CREATEDBY,map_id,'OPEN',map_id,'B51UT0' from Ob_visitTask where visittask_guid='"+v_BusNum+"'"
                  def updatesqlresult47=eliteBean.update(updatesql47,"dataSource")
                  log.debug("updatesqlresult47:"+updatesqlresult47)
                  //生成 elitetask
                  def updatesql48="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID, CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG) select sysguid,objective_guid,'USZP59',sysdate,'OPEN','NORMAL','ORG016',CREATEDBY,CREATEDDATE,'"+ba_custguid+"','OPEN','B51UT0',MAP_ID,'OPEN','OPEN','1' FROM Ob_visitTask where visittask_guid='"+v_BusNum+"'"
                  def updatesqlresult48=eliteBean.update(updatesql48,"dataSource")
                  log.debug("updatesqlresult48:"+updatesqlresult48)
                }
                  //报案--自助理赔回访
                if(V_BUSTYPE_REPORT=='ZZLP'){
                    //生成 objective
                  def updatesql49="insert into objective (OBJECTIVE_GUID, OBJECTIVETYPE_ID, HANDLEGROUP_ID,PRIORITY_ID,EXPIREDDATE,CUSTOMER_GUID,OBJECTIVESTATUS,FIRSTCONTACTDATE,LASTCONTACTDATE,CREATEDDATE,CREATEDBY,WORKORDERFRAME_ID,OBJECTIVESUBSTATUS,MAP_ID,CURSTEP_ID_MAP)select objective_guid,'USZP59','ORG016','NORMAL',sysdate,'"+ba_custguid+"','OPEN',to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),CREATEDDATE,CREATEDBY,map_id,'OPEN',map_id,'R41IZC' from Ob_visitTask where visittask_guid='"+v_BusNum+"'"
                  def updatesqlresult49=eliteBean.update(updatesql49,"dataSource")
                  log.debug("updatesqlresult49:"+updatesqlresult49)
                  //生成 elitetask
                  def updatesql50="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID, CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG) select sysguid,objective_guid,'USZP59',sysdate,'OPEN','NORMAL','ORG016',CREATEDBY,CREATEDDATE,'"+ba_custguid+"','OPEN','R41IZC',MAP_ID,'OPEN','OPEN','1' FROM Ob_visitTask where visittask_guid='"+v_BusNum+"'"
                  def updatesqlresult50=eliteBean.update(updatesql50,"dataSource")
                  log.debug("updatesqlresult50:"+updatesqlresult50)
                }
            }
            //有客户
            if(countba>0){
                //获取customer_guid
              def querysql51="select cc.customer_guid v_ba_custguid  from customer cc ,(select sd.insuredname a,sd.mobile b from Ob_visitTask v left join dh_POLICY sd on sd.PolicyNo=v.businessno where  v.visittask_guid= '"+v_BusNum+"')tt where cc.customername=tt.a and cc.mobile=tt.b and rownum=1"
              def v_ba_custguid="insert into customer(CUSTOMER_GUID,customertype_id,CUSTOMERNAME,MOBILE,WORKSTATUS)select '"+ba_custguid+"','KFjoin',C.reportor_name a,C.reportor_phone b,'ONLINE' from Ob_visitTask t left join DH_REPORT c on c.CLM_NO=t.BUSINESSNO where visittask_guid= '"+v_BusNum+"'  and rownum=1"
              def list51=eliteBean.chaxun_sql(querysql51,"dataSource")
              log.debug("list51-------------------------------"+list51)
			  def map51=list51[0]
              log.debug("map51-------------------------------"+map51)
              def ba_custguid=map51.get("v_ba_custguid")
              log.debug("ba_custguid-------------------------------"+ba_custguid)
                  //报案--现场查勘回访
                if(V_BUSTYPE_REPORT=='DDF'){
                    //生成 objective
                  def updatesql52="insert into objective (OBJECTIVE_GUID, OBJECTIVETYPE_ID, HANDLEGROUP_ID,PRIORITY_ID,EXPIREDDATE,CUSTOMER_GUID,OBJECTIVESTATUS,FIRSTCONTACTDATE,LASTCONTACTDATE,CREATEDDATE,CREATEDBY,WORKORDERFRAME_ID,OBJECTIVESUBSTATUS,MAP_ID,CURSTEP_ID_MAP)select objective_guid,'USZP59','ORG016','NORMAL',sysdate,'"+ba_custguid+"','OPEN',to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),CREATEDDATE,CREATEDBY,map_id,'OPEN',map_id,'UUANWS' from Ob_visitTask where visittask_guid='"+v_BusNum+"'"
                  def updatesqlresult52=eliteBean.update(updatesql52,"dataSource")
                  log.debug("updatesqlresult52:"+updatesqlresult52)
                  //生成 elitetask
                  def updatesql53="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID, CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG) select sysguid,objective_guid,'USZP59',sysdate,'OPEN','NORMAL','ORG016',CREATEDBY,CREATEDDATE,'"+ba_custguid+"','OPEN','UUANWS',MAP_ID,'OPEN','OPEN','1' FROM Ob_visitTask where visittask_guid='"+v_BusNum+"'"
                  def updatesqlresult53=eliteBean.update(updatesql53,"dataSource")
                  log.debug("updatesqlresult53:"+updatesqlresult53)
                }
                  //报案--非现场查勘回访
                if(V_BUSTYPE_REPORT=='DDE'){
                    //生成 objective
                  def updatesql56="insert into objective (OBJECTIVE_GUID, OBJECTIVETYPE_ID, HANDLEGROUP_ID,PRIORITY_ID,EXPIREDDATE,CUSTOMER_GUID,OBJECTIVESTATUS,FIRSTCONTACTDATE,LASTCONTACTDATE,CREATEDDATE,CREATEDBY,WORKORDERFRAME_ID,OBJECTIVESUBSTATUS,MAP_ID,CURSTEP_ID_MAP)select objective_guid,'USZP59','ORG016','NORMAL',sysdate,'"+ba_custguid+"','OPEN',to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),CREATEDDATE,CREATEDBY,map_id,'OPEN',map_id,'B51UT0' from Ob_visitTask where visittask_guid='"+v_BusNum+"'"
                  def updatesqlresult56=eliteBean.update(updatesql56,"dataSource")
                  log.debug("updatesqlresult56:"+updatesqlresult56)
                  //生成 elitetask
                  def updatesql57="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID, CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG) select sysguid,objective_guid,'USZP59',sysdate,'OPEN','NORMAL','ORG016',CREATEDBY,CREATEDDATE,'"+ba_custguid+"','OPEN','B51UT0',MAP_ID,'OPEN','OPEN','1' FROM Ob_visitTask where visittask_guid='"+v_BusNum+"'"
                  def updatesqlresult57=eliteBean.update(updatesql57,"dataSource")
                  log.debug("updatesqlresult57:"+updatesqlresult57)
                }
                  //报案--自助理赔回访
                if(V_BUSTYPE_REPORT=='ZZLP'){
                    //生成 objective
                  def updatesql58="insert into objective (OBJECTIVE_GUID, OBJECTIVETYPE_ID, HANDLEGROUP_ID,PRIORITY_ID,EXPIREDDATE,CUSTOMER_GUID,OBJECTIVESTATUS,FIRSTCONTACTDATE,LASTCONTACTDATE,CREATEDDATE,CREATEDBY,WORKORDERFRAME_ID,OBJECTIVESUBSTATUS,MAP_ID,CURSTEP_ID_MAP)select objective_guid,'USZP59','ORG016','NORMAL',sysdate,'"+ba_custguid+"','OPEN',to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),to_date('"+v_CallTime+"','yyyy-mm-dd hh24:mi:ss'),CREATEDDATE,CREATEDBY,map_id,'OPEN',map_id,'R41IZC' from Ob_visitTask where visittask_guid='"+v_BusNum+"'"
                  def updatesqlresult58=eliteBean.update(updatesql58,"dataSource")
                  log.debug("updatesqlresult58"+updatesqlresult58)
                  //生成 elitetask
                  def updatesql59="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID, CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG) select sysguid,objective_guid,'USZP59',sysdate,'OPEN','NORMAL','ORG016',CREATEDBY,CREATEDDATE,'"+ba_custguid+"','OPEN','R41IZC',MAP_ID,'OPEN','OPEN','1' FROM Ob_visitTask where visittask_guid='"+v_BusNum+"'"
                  def updatesqlresult59=eliteBean.update(updatesql59,"dataSource")
                  log.debug("updatesqlresult59:"+updatesqlresult59)
                }
            }*/
          //返回成功结果
          JSONObject  jsonALL3 = new JSONObject();
          jsonALL3.put("code", "200");
          jsonALL3.put("msg", "success");
          return jsonALL3;
        }       

        else{
            //返回失败结果
            JSONObject  jsonALL3 = new JSONObject();
                jsonALL3.put("code", "400");
                jsonALL3.put("msg", "failure");
                return jsonALL3;
        }
      }  
        
  }
}
